package top.atcra.rpc.transport.config;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import lombok.extern.slf4j.Slf4j;
import top.atcra.rpc.transport.common.MethodCaller;
import top.atcra.rpc.transport.request.RPCRequestDecoder;
import top.atcra.rpc.transport.response.RPCResponseEncoder;

@Slf4j
public class ServerRPCChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        var pipe = ch.pipeline();
//        pipe.addLast(new LoggingHandler(log.isDebugEnabled() ? LogLevel.DEBUG : LogLevel.INFO))
//        pipe.addLast(new LoggingHandler());
        pipe.addLast(new RPCRequestDecoder())
                .addLast(new MethodCaller())
                .addLast(new RPCResponseEncoder());
    }
}
